import {takeEvery,put} from 'redux-saga/effects'
import { GET_INIT_LIST } from './actionTypes';
import axios from 'axios';
import {InitListAction} from './actionCreator'

function* getInitList() {
    try {
        const res = yield axios.get('/list.json');
        const action = InitListAction(res.data);
        yield put(action);
    } catch (e) {
        console.error('failed')
    }
}

function* mySaga() {
    // 捕捉每一个every的类型
    // 如果 USER_FETCH_REQUESTED === GET_INIT_LIST 的话，也就是说接收到GET_INIT_LIST
    // 就会执行 getInitList 这个方法
    yield takeEvery(GET_INIT_LIST, getInitList);
}
  
export default mySaga;